package com.study.zzedu.widget;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.study.zzedu.R;
import com.study.zzedu.ui.choicecourse.ChoiceCourseActivity;

public class ChoiceCourseDialog extends Dialog {

    public ChoiceCourseDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    public static class Builder {

        private View mLayout;

        private Button btn_cancel,btn_yes;
        private TextView tv_warn;

        private View.OnClickListener mButtonClickListener;

        private ChoiceCourseDialog mDialog;

        public Builder(final Context context,String term) {
            mDialog = new ChoiceCourseDialog(context, R.style.Theme_AppCompat_Dialog);
            LayoutInflater inflater =
                    (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            //加载布局文件
            mLayout = inflater.inflate(R.layout.choice_course_dialog, null, false);
            //添加布局文件到 Dialog
            mDialog.addContentView(mLayout, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT));

            mDialog.setCanceledOnTouchOutside(false);
            btn_yes = mLayout.findViewById(R.id.btn_yes);
            btn_cancel = mLayout.findViewById(R.id.btn_cancel);
            tv_warn = mLayout.findViewById(R.id.tv_warn);
            tv_warn.setText("当前"+term+"已开始\n快来选你中意的选修课吧");
            btn_yes.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mDialog.dismiss();
                    context.startActivity(new Intent(context, ChoiceCourseActivity.class));
                }
            });
            btn_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(mDialog != null)
                        mDialog.cancel();
                }
            });
        }

        /**
         * 设置按钮文字和监听
         */
        public Builder setButton(View.OnClickListener listener) {
            mButtonClickListener = listener;
            return this;
        }

        public ChoiceCourseDialog create() {
            return mDialog;
        }
    }
}